package com.cayte.photo.get;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.Toast;

import com.cayte.photo.get.CayteGetFile.OnSelectFile;

public class MainActivity extends Activity {

	CayteGetFile getFile;
	ImageView image;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		image = (ImageView) findViewById(R.id.image);

		getFile = new CayteGetFile(this);

		String dir = Environment.getExternalStorageDirectory().getPath()
				+ File.separator + "Cayte" + File.separator;
		File d = new File(dir);
		if (!d.exists())
			d.mkdir();

		getFile.create(Environment.getExternalStorageDirectory().getPath()
				+ File.separator + "Cayte" + File.separator);

		getFile.setOnSelectFile(new OnSelectFile() {

			@Override
			public void onSelect(String name, String path) {
				// TODO Auto-generated method stub
				System.out.println(path);
				Toast.makeText(MainActivity.this, path, Toast.LENGTH_SHORT)
						.show();
				CayteOpenFile.openFile(MainActivity.this, path);
			}
		});

		image.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				getFile.selectFile();
			}
		});
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		getFile.onActivityResult(requestCode, resultCode, data);
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}
}
